"""
平衡车 商品信息页面
"""
import time
from common.Base import open_browser, Base

goods_url = "http://localhost:8080/ecshop/goods.php?id=69"


class GoodsInfoPage(Base):
    goods_name_location = ("class name", "goods_style_name")  # 定位商品名称：平衡车
    goods_num_location = ("xpath", "//*[@id='ECS_FORMBUY']/ul/li[1]/dd[1]")  # 定位平衡车的商品货号
    goods_stock_location = ("xpath", "//*[@id='ECS_FORMBUY']/ul/li[1]/dd[2]")  # 定位平衡车的商品库存
    goods_brand_location = ("xpath", "//*[@id='ECS_FORMBUY']/ul/li[2]/dd[1]/a")  # 定位平衡车的商品品牌
    goods_weight_location = ("css selector", "#ECS_FORMBUY > ul > li:nth-child(2) > dd.ddR")  # 定位平衡车的商品重量
    goods_uptime_location = ("css selector", "#ECS_FORMBUY > ul > li:nth-child(3) > dd:nth-child(1)")  # 定位平衡车的上架时间
    goods_click_num_location = ("css selector", "#ECS_FORMBUY > ul > li:nth-child(3) > dd:nth-child(2)")  # 定位平衡车的点击次数
    goods_sales_location = ("css selector", "#ECS_FORMBUY > ul > li:nth-child(3) > dd:nth-child(3)")  # 定位平衡车的累计销量
    goods_market_location = ("class name", "market")  # 定位平衡车的市场价格
    goods_price_location = ("id", "ECS_SHOPPRICE")  # 定位平衡车的本店售价
    goods_reg_price_location = ("id", "ECS_RANKPRICE_1")  # 定位平衡车的注册用户价格
    goods_vip_price_location = ("id", "ECS_RANKPRICE_2")  # 定位平衡车的vip用户价格
    goods_amount_location = ("id", "ECS_GOODS_AMOUNT")  # 定位平衡车的商品总价
    goods_integral_location = ("class name", "f4")  # 定位平衡车的商品可使用积分
    goods_number_location = ("id", "number")  # 定位平衡车购买数量

    # 获取商品名称
    def goods_name(self):
        return self.get_element_text(self.goods_name_location)

    # 获取的商品货号
    def goods_num(self):
        return self.get_element_text(self.goods_num_location)

    # 获取的商品库存
    def goods_stock(self):
        return self.get_element_text(self.goods_stock_location)

    # 获取的商品品牌
    def goods_brand(self):
        return self.get_element_text(self.goods_brand_location)

    # 获取商品重量
    def goods_weight(self):
        return self.get_element_text(self.goods_weight_location)

    # 获取商品的上架时间
    def goods_uptime(self):
        return self.get_element_text(self.goods_uptime_location)

    # 商品的点击次数
    def goods_click_num(self):
        return self.get_element_text(self.goods_click_num_location)

    # 商品的点击次数
    def goods_sales(self):
        return self.get_element_text(self.goods_sales_location)

    # 商品的市场价格
    def goods_market(self):
        return self.get_element_text(self.goods_market_location)

    # 商品的本店售价
    def goods_price(self):
        return self.get_element_text(self.goods_price_location)

    # 商品的注册用户价格
    def goods_reg_price(self):
        return self.get_element_text(self.goods_reg_price_location)

    # 商品的vip用户价格
    def goods_vip_price(self):
        return self.get_element_text(self.goods_vip_price_location)

    # 商品的总价
    def goods_amount(self):
        time.sleep(3)
        return self.get_element_text(self.goods_amount_location)

    # 商品的可使用积分
    def goods_integral(self):
        return self.get_element_text(self.goods_integral_location)

    # 商品的购买数量
    def goods_number(self, number):
        self.clear_send_text(self.goods_number_location, number)


if __name__ == '__main__':
    driver = open_browser()
    lp = GoodsInfoPage(driver)
    lp.open_url(goods_url)
    # lp.goods_number(1)
    print(lp.goods_stock())
